using System;
using System.Collections.Generic;
using System.Text;

using CMS.Data;
using CMS.Core.Domain;
using CMS.Core.DataInterfaces;
using CMS.Presenters.Views;
using AjaxPro;
using CMS.Core.DataInterfaces;
using CMS.Presenters.Views;

namespace CMS.Presenters.Presenters
{
    public class VBPLPresenter
    {
        private List<VanBan> objList;
        private IVBPLView iObjView;
        private IVanBanDao iObjDAO;
        
        /// <summary>
        /// Raised when the user wants to cancel editing a object.  The containing ASPX page should 
        /// listen for this event.
        /// </summary>
        public EventHandler CancelUpdateEvent;

        /// <summary>
        /// Raised after the object has been successfully committed to the database. 
        /// </summary>
        public EventHandler UpdateCompleteEvent;

        //Attaches this presenter to the view's events.
        public VBPLPresenter(IVBPLView iObjView, IVanBanDao iObjDAO)
        {
            if (iObjView == null) throw new ArgumentNullException("View may not be null");
            if (iObjDAO == null) throw new ArgumentNullException("LinhVucDao may not be null");
            this.iObjView = iObjView;
            this.iObjDAO = iObjDAO;

            SubscribeViewToEvents();
        }

        public VBPLPresenter() { 
        
        }


        void SubscribeViewToEvents()
        {
            iObjView.Load += OnViewLoad;
        }

        void OnViewLoad(object sender, EventArgs e)
        {
             //LoadViewFromModel();
        }

        public void LoadViewFromModel(string maChucNang, bool valueChucNang)
        {
            this.objList = this.iObjDAO.GetAllWithMoreFieldsAndOderBy(true, new string[] { maChucNang } , new Object[] { valueChucNang } , new string[] { "NgayKy" } , true);
            iObjView.VanBanList = objList;           
        }                        
    }
}
